package cc.wanforme.chipmunity.common.bean;


import cc.wanforme.chipmunity.common.bean.constant.CommonResponse;
import cc.wanforme.chipmunity.common.bean.constant.HttpResponseStatusEnum;

/**HTTP 统一响应结果
 * @author wanne
 * 2019年7月23日
 * 
 */
public class WebResponse {

    /**
     * 响应码
     */
    private String code;

    /**
     * 提示信息（提示信息不一定是枚举类型对应的说明，可以修改）
     */
    private String message;

    /**
     * 结果
     */
    private Object result;

    public WebResponse() {}
    
    public WebResponse(String code, String message, Object result) {
		super();
		this.code = code;
		this.message = message;
		this.result = result;
	}

	public WebResponse(HttpResponseStatusEnum httpResponseStatusEnum) {
        this.code = httpResponseStatusEnum.getCode();
        this.message = httpResponseStatusEnum.getMessage();
    }

    public WebResponse(CommonResponse commonResponse) {
        this.code = commonResponse.getCode();
        this.message = commonResponse.getMessage();
    }

    
    
    /**
     * 成功响应
     */
    public static WebResponse success() {
        return new WebResponse(HttpResponseStatusEnum.SUCCESS.getCode(), HttpResponseStatusEnum.SUCCESS.getMessage(), null);
    }

    /**
     * 成功响应
     */
    public static WebResponse success(String msg) {
        return new WebResponse(HttpResponseStatusEnum.SUCCESS.getCode(), msg, null);
    }
    
    /**
     * 成功响应
     */
    public static WebResponse success(String msg, Object object) {
        return new WebResponse(HttpResponseStatusEnum.SUCCESS.getCode(), msg, null);
    }

    
    /**
     * 响应失败
     * */
    public static WebResponse fail() {
    	return new WebResponse(HttpResponseStatusEnum.FAIL.getCode(), HttpResponseStatusEnum.FAIL.getMessage(), null);
    }
    
    /**
     * 响应失败
     * */
    public static WebResponse fail(String msg) {
    	return new WebResponse(HttpResponseStatusEnum.FAIL.getCode(), msg, null);
    }
   
    /**
     * 响应失败
     * */
    public static WebResponse fail(String msg, Object result) {
    	return new WebResponse(HttpResponseStatusEnum.FAIL.getCode(), msg, result);
    }

    /**
     * 禁止操作
     */
    public static WebResponse forbidden() {
        return new WebResponse(HttpResponseStatusEnum.FORBIDDEN_OPERATION.getCode(), HttpResponseStatusEnum.FORBIDDEN_OPERATION.getMessage(), null);
    }

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}
    
}
